package net.sureon.common;

/**
 * This class allows you to pass a long by reference and allow the receiver to
 * modify it.
 * 
 * @author jason
 * 
 */
public class BoxedLong {
	private long longVal = 0;

	/* various constructors */
	public BoxedLong(long longVal) {
		this.longVal = longVal;
	}

	public BoxedLong() {
	}

	public BoxedLong(String strLongVal) {
		/* note: this can throw a number format exception */
		longVal = Long.parseLong(strLongVal);
	}

	/**
	 * @return the value as a long.
	 */
	public long getLongValue() {
		return longVal;
	}

	/**
	 * @param longVal
	 *            the value to be set
	 */
	public void setLongValue(long longVal) {
		this.longVal = longVal;
	}

	/**
	 * Increment the internal long, then return the incremented value.
	 * 
	 * @return incremented value.
	 */
	public long increment() {
		longVal++;
		return longVal;
	}

	/**
	 * Decrement the internal long, then return the decremented value.
	 * 
	 * @return decremented value.
	 */
	public long decrement() {
		longVal--;
		return longVal;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return Long.toString(longVal);
	}
}
